package com.learn.controller;

import cn.hutool.core.date.DateUtil;
import com.learn.apis.PayFeignApi;
import com.learn.entities.PayDTO;
import com.learn.resp.Result;
import jakarta.annotation.Resource;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/07/31
 * @description
 */
@RestController
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping("/feign/pay/add")
    public Result addOrder(@RequestBody PayDTO payDTO) {
        return payFeignApi.addPay(payDTO);
    }

    @DeleteMapping("/feign/pay/del/{id}")
    public Result deletePayById(@PathVariable("id") Integer id) {
        return payFeignApi.deletePayById(id);
    }

    @PutMapping("/feign/pay/update")
    public Result updatePayById(@RequestBody PayDTO payDTO) {
        return payFeignApi.updatePayById(payDTO);
    }

    /**
     * 测试超时和报错
     * @param id
     * @return
     */
    @GetMapping("/feign/pay/get/{id}")
    public Result selectOneById(@PathVariable("id") Integer id) {
        try {
            System.out.println("===============: " + DateUtil.now());
            return payFeignApi.selectOneById(id);
        } catch (Exception e) {
            System.out.println("===============: " + DateUtil.now());
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/feign/info")
    public String getInfo() {
        return payFeignApi.getInfo();
    }
}
